package thread;

public class SyncDemo1 {
    public static boolean success1=false;
    public static boolean success2=false;

    public static void main(String[] args) {
        int num=0;
        Bank bank = new Bank();
        while(true){
            num++;

        Thread t1=new Thread("张三"){
            public void run(){
                success1=bank.getMoney(20000);
            }
        };
        Thread t2=new Thread("鲁肃"){
            public void run(){
                success2=bank.getMoney(20000);
            }
        };
        t1.start();
        t2.start();
        try {
            Thread.sleep(5);
        } catch (InterruptedException e) {

        }
        if(success1&&success2){
            System.out.println("出现了问题！");
            System.out.println("总共尝试了"+num+"次！");
            break;
        }else{
            System.out.println("没有出现问题！");
            bank.setAccount(20000);
        }
        }
    }
}
